/**
 * 作者: wgx
 * 日期: 2024-12-31 17:00:17
 * 备注: 用户子嗣模块表
 */
package com.motu.monstercity.server.game.userdata;

import com.motu.monstercity.protocol.Common.PBUserChildInfo;
import com.motu.vertx.module.utility.model.BaseModel;
import com.motu.vertx.module.utility.model.Model;
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;

public class UserChildInfoModel extends BaseModel implements Model {
    public static final String LISTKEY = "";
    public static final int REDIS_EXPIRE_TIME = 0;// redis过期时间
    public static final int UPDATE_DB_TYPE = UPDATE_DB_TYPE_QUEUE;// 数据入库类型 队列入库
    public static final boolean ORDER_LIST = false;// 是否需要额外的有序列表

    protected long id; // 玩家id
    protected int graduationNum; // 毕业子嗣数量
    protected int marryNum; // 已婚子嗣数量
    protected int aloneNum; // 孤独终老的子嗣数量
    protected int childNum; // 子嗣总数量
    protected long maxEarnAdd; // 子嗣历史最高城市收益
    protected String maxEarnAddInfo = ""; // 子嗣历史最高城市收益的子嗣快照 (jsonobjec格式的字符串)
    protected int isRefuseMarryApply; // 是否拒绝接收联姻请求 (0-不拒绝可以接收，1-拒绝接收)
    protected int isHaveDating; // 是否已经约会过 (1-是，0-首次约好必定生小孩)
    protected int isFirstChild; // 第一个小孩毕业必定不是不婚主义，引导用

    public void reset() {
    }

    protected String getKey() {
        return "UserChildInfo." + id;
    }

    protected String getListKey() {
        return null;
    }

    protected String getListItemKey() {
        return null;
    }

    public void doCreate() {
        setTableId();
        insert();
    }

    public void setTableId() {
        putId(incrTableId("user_child_info"));
    }

    public JsonObject insert() {
        return super.insert(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
    }

    public void delete() {
        super.delete(getKey(), id, UPDATE_DB_TYPE, id, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
    }

    /**
     * 根据入库类型更新
     */
    public JsonObject update() {
        return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, id, getAllObj(), LISTKEY, getListKey(), getListItemKey());
    }

    /**
     * 实时入队列
     */
    public JsonObject updateQueueNow() {
        return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, 0, getAllObj(), LISTKEY, getListKey(), getListItemKey());
    }

    public JsonObject getAllObj(){
        JsonObject obj = new JsonObject();
        obj.put("id", id); // 玩家id
        obj.put("graduationNum", graduationNum); // 毕业子嗣数量
        obj.put("marryNum", marryNum); // 已婚子嗣数量
        obj.put("aloneNum", aloneNum); // 孤独终老的子嗣数量
        obj.put("childNum", childNum); // 子嗣总数量
        obj.put("maxEarnAdd", maxEarnAdd); // 子嗣历史最高城市收益
        obj.put("maxEarnAddInfo", maxEarnAddInfo); // 子嗣历史最高城市收益的子嗣快照 (jsonobjec格式的字符串)
        obj.put("isRefuseMarryApply", isRefuseMarryApply); // 是否拒绝接收联姻请求 (0-不拒绝可以接收，1-拒绝接收)
        obj.put("isHaveDating", isHaveDating); // 是否已经约会过 (1-是，0-首次约好必定生小孩)
        obj.put("isFirstChild", isFirstChild); // 是否已经生过小孩 (1-是，0-首次生小孩必定不是不婚主义，引导用)
        return obj;
    }

    public PBUserChildInfo.Builder takeInitBuilder() {
        PBUserChildInfo.Builder sb = PBUserChildInfo.newBuilder();
        if (graduationNum != 0) {
            sb.setGraduationNum(graduationNum);
        }
        if (marryNum != 0) {
            sb.setMarryNum(marryNum);
        }
        if (isRefuseMarryApply != 0) {
            sb.setIsRefuseMarryApply(isRefuseMarryApply);
        }
        return sb;
    }

    public PBUserChildInfo.Builder takeBuilder() {
        if (updateObj == null || updateObj.isEmpty()) {
            return takeInitBuilder();
        }
        PBUserChildInfo.Builder sb = PBUserChildInfo.newBuilder();
        if (isFieldUpdate("graduationNum")) {
            sb.setGraduationNum(graduationNum);
        }
        if (isFieldUpdate("marryNum")) {
            sb.setMarryNum(marryNum);
        }
        if (isFieldUpdate("isRefuseMarryApply")) {
            sb.setIsRefuseMarryApply(isRefuseMarryApply);
        }
        return sb;
    }

    public long getId() {
        return id;
    }

    public void putId(long id) {
        if (this.id != id) {
            this.id = id;
            updateRedisHashField(getKey(), "id", this.id);
        }
    }

    public void addId(long value) {
        this.id += value;
        updateRedisHashField(getKey(), "id", this.id);
    }

    public int getGraduationNum() {
        return graduationNum;
    }

    public void putGraduationNum(int graduationNum) {
        if (this.graduationNum != graduationNum) {
            this.graduationNum = graduationNum;
            updateRedisHashField(getKey(), "graduationNum", this.graduationNum);
        }
    }

    public void addGraduationNum(int value) {
        this.graduationNum += value;
        updateRedisHashField(getKey(), "graduationNum", this.graduationNum);
    }

    public int getMarryNum() {
        return marryNum;
    }

    public void putMarryNum(int marryNum) {
        if (this.marryNum != marryNum) {
            this.marryNum = marryNum;
            updateRedisHashField(getKey(), "marryNum", this.marryNum);
        }
    }

    public void addMarryNum(int value) {
        this.marryNum += value;
        updateRedisHashField(getKey(), "marryNum", this.marryNum);
    }

    public int getAloneNum() {
        return aloneNum;
    }

    public void putAloneNum(int aloneNum) {
        if (this.aloneNum != aloneNum) {
            this.aloneNum = aloneNum;
            updateRedisHashField(getKey(), "aloneNum", this.aloneNum);
        }
    }

    public void addAloneNum(int value) {
        this.aloneNum += value;
        updateRedisHashField(getKey(), "aloneNum", this.aloneNum);
    }

    public int getChildNum() {
        return childNum;
    }

    public void putChildNum(int childNum) {
        if (this.childNum != childNum) {
            this.childNum = childNum;
            updateRedisHashField(getKey(), "childNum", this.childNum);
        }
    }

    public void addChildNum(int value) {
        this.childNum += value;
        updateRedisHashField(getKey(), "childNum", this.childNum);
    }

    public long getMaxEarnAdd() {
        return maxEarnAdd;
    }

    public void putMaxEarnAdd(long maxEarnAdd) {
        if (this.maxEarnAdd != maxEarnAdd) {
            this.maxEarnAdd = maxEarnAdd;
            updateRedisHashField(getKey(), "maxEarnAdd", this.maxEarnAdd);
        }
    }

    public void addMaxEarnAdd(long value) {
        this.maxEarnAdd += value;
        updateRedisHashField(getKey(), "maxEarnAdd", this.maxEarnAdd);
    }

    public String getMaxEarnAddInfo() {
        return maxEarnAddInfo;
    }

    public void putMaxEarnAddInfo(String maxEarnAddInfo) {
        if (!this.maxEarnAddInfo.equals(maxEarnAddInfo)) {
            this.maxEarnAddInfo = maxEarnAddInfo;
            updateRedisHashField(getKey(), "maxEarnAddInfo", this.maxEarnAddInfo);
        }
    }

    public int getIsRefuseMarryApply() {
        return isRefuseMarryApply;
    }

    public void putIsRefuseMarryApply(int isRefuseMarryApply) {
        if (this.isRefuseMarryApply != isRefuseMarryApply) {
            this.isRefuseMarryApply = isRefuseMarryApply;
            updateRedisHashField(getKey(), "isRefuseMarryApply", this.isRefuseMarryApply);
        }
    }

    public void addIsRefuseMarryApply(int value) {
        this.isRefuseMarryApply += value;
        updateRedisHashField(getKey(), "isRefuseMarryApply", this.isRefuseMarryApply);
    }

    public int getIsHaveDating() {
        return isHaveDating;
    }

    public void putIsHaveDating(int isHaveDating) {
        if (this.isHaveDating != isHaveDating) {
            this.isHaveDating = isHaveDating;
            updateRedisHashField(getKey(), "isHaveDating", this.isHaveDating);
        }
    }

    public void addIsHaveDating(int value) {
        this.isHaveDating += value;
        updateRedisHashField(getKey(), "isHaveDating", this.isHaveDating);
    }

    public int getIsFirstChild() {
        return isFirstChild;
    }

    public void putIsFirstChild(int isFirstChild) {
        if (this.isFirstChild != isFirstChild) {
            this.isFirstChild = isFirstChild;
            updateRedisHashField(getKey(), "isFirstChild", this.isFirstChild);
        }
    }

    public void addIsFirstChild(int value) {
        this.isFirstChild += value;
        updateRedisHashField(getKey(), "isFirstChild", this.isFirstChild);
    }

}